package com.wc.dao.bean;

import com.alibaba.fastjson.JSON;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.util.List;

/**
 * 用户单击页码时，服务器端返回的数据
 *
 * @param <T>
 */
@Getter
@Setter
@NoArgsConstructor
public class PageBean<T> {
    /**
     * 每页显示的条数
     */
    private Integer pageSize = 10;
    /**
     * 当前的页码
     */
    private Integer pageNum;
    /**
     * 一共有多少条记录
     */
    private Integer total;
    /**
     * 一共有多少页
     */
    private Integer pages;
    /**
     * 每一页所显示的数据
     */
    private List<T> records;

    public PageBean(Integer pageNum, Integer pageSize, Integer total, List<T> records) {
        this.pageSize = pageSize;
        this.pageNum = pageNum;
        this.total = total;
        this.pages = this.total % this.pageSize == 0 ? this.total / this.pageSize : this.total / this.pageSize + 1;
        this.records = records;
    }

    @Override
    public String toString() {
        //返回当前对象的JSON字符串
        return JSON.toJSONString(this);
    }
}
